package com.ctsi.ssdc.admin.domain.dto;

import java.io.Serializable;

import org.apache.commons.lang3.StringUtils;

import com.ctsi.ssdc.admin.domain.CscpRolesExample.Criteria;
import com.ctsi.ssdc.criteria.IntegerCriteria;
import com.ctsi.ssdc.criteria.StringCriteria;

/**
 * Criteria for the entity CscpRoles
 *
 * @author ctsi biyi generator
 *
 */
public class CscpRolesCriteria implements Serializable {

	private static final long serialVersionUID = 1L;

	private IntegerCriteria id;
	private StringCriteria name;
	private StringCriteria roleExtent;
	private IntegerCriteria parentId;
	private StringCriteria icon;

	public IntegerCriteria getId() {
		return id;
	}

	public void setId(IntegerCriteria id) {
		this.id = id;
	}

	public StringCriteria getName() {
		return name;
	}

	public void setName(StringCriteria name) {
		this.name = name;
	}

	public StringCriteria getRoleExtent() {
		return roleExtent;
	}

	public void setRoleExtent(StringCriteria roleExtent) {
		this.roleExtent = roleExtent;
	}

	public IntegerCriteria getParentId() {
		return parentId;
	}

	public void setParentId(IntegerCriteria parentId) {
		this.parentId = parentId;
	}

	public StringCriteria getIcon() {
		return icon;
	}

	public void setIcon(StringCriteria icon) {
		this.icon = icon;
	}

	public Criteria buildCriteria(Criteria criteria) {
		if (criteria == null) {
			return criteria;
		}
		
		this.buildIdCriteria(criteria);
		this.buildNameCriteria(criteria);
		this.buildRoleExtentCriteria(criteria);
		this.buildParentIdCriteria(criteria);
		this.buildIconCriteria(criteria);

		return criteria;
	}

	private void buildIdCriteria(Criteria criteria) {

		if (this.getId() == null) {
			return;
		}

		if (this.getId().getEquals() != null) {
			criteria.andIdEqualTo(this.getId().getEquals());
		} else {

			if (this.getId().getGreaterOrEqualThan() != null) {
				criteria.andIdGreaterThanOrEqualTo(this.getId().getGreaterOrEqualThan());
			}

			if (this.getId().getLessOrEqualThan() != null) {
				criteria.andIdLessThanOrEqualTo(this.getId().getLessOrEqualThan());
			}
		}
	}

	private void buildNameCriteria(Criteria criteria) {

		if (this.getName() == null) {
			return;
		}

		if (this.getName().getEquals() != null) {
			criteria.andNameEqualTo(this.getName().getEquals());
		} else {
			if (StringUtils.isNotBlank(this.getName().getContains())) {
				criteria.andNameLike(String.format("%%%s%%", this.getName().getContains()));
			}
		}
	}

	private void buildRoleExtentCriteria(Criteria criteria) {

		if (this.getRoleExtent() == null) {
			return;
		}

		if (this.getRoleExtent().getEquals() != null) {
			criteria.andRoleExtentEqualTo(this.getRoleExtent().getEquals());
		} else {
			if (StringUtils.isNotBlank(this.getRoleExtent().getContains())) {
				criteria.andRoleExtentLike(String.format("%%%s%%", this.getRoleExtent().getContains()));
			}
		}
	}

	private void buildParentIdCriteria(Criteria criteria) {

		if (this.getParentId() == null) {
			return;
		}

		if (this.getParentId().getEquals() != null) {
			criteria.andParentIdEqualTo(this.getParentId().getEquals());
		} else {

			if (this.getParentId().getGreaterOrEqualThan() != null) {
				criteria.andParentIdGreaterThanOrEqualTo(this.getParentId().getGreaterOrEqualThan());
			}

			if (this.getParentId().getLessOrEqualThan() != null) {
				criteria.andParentIdLessThanOrEqualTo(this.getParentId().getLessOrEqualThan());
			}
		}
	}

	private void buildIconCriteria(Criteria criteria) {

		if (this.getIcon() == null) {
			return;
		}

		if (this.getIcon().getEquals() != null) {
			criteria.andIconEqualTo(this.getIcon().getEquals());
		} else {
			if (StringUtils.isNotBlank(this.getIcon().getContains())) {
				criteria.andIconLike(String.format("%%%s%%", this.getIcon().getContains()));
			}
		}
	}

}
